package com.banmajio.mapper;

import com.banmajio.bean.Kdp01;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@DS("slave")
@Mapper
public interface Kdp01Mapper extends BaseMapper<Kdp01> {

    Integer getCount();

    List<Kdp01> getByPage(@Param("page") Integer page);

    @Select("select " +
            "  COUNT(distinct  (t.axcp0005) ) " +
            "from " +
            "  ${tableName} t " +
            "where " +
            "  (exists ( " +
            "  select " +
            "    1 " +
            "  from " +
            "    ${tableName} t2 " +
            "  where " +
            "    t2.axcp0005 = t.axcp0005 " +
            "  limit 1) " +
            "  and axcp0077 = '0' " +
            "  and axcp0004 = '01' " +
            "  and is_delete = '0' " +
            "  and LENGTH(axcp0005) = 18 " +
            "    and axcp0005 not like '% %') ")
//    @Select("SELECT COUNT(*) AS count FROM ${tableName}")
    List<Map<String, Object>> selectCounts(@Param("tableName") String tableName);


    @Select("SELECT *, ctid FROM ${tableName} ${ew.customSqlSegment}")
    List<Map<String, Object>> selectMapsByWrapper(
            @Param("tableName") String tableName,
            @Param("ew") com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<Kdp01> queryWrapper
    );
}
